package com.tj.collection.db.dao;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.BaseMapper;
import com.tj.collection.db.entity.ClAllocationDetailEntity;
import com.tj.collection.db.entity.business.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2019-09-03
 * Time: 10:18
 */
public interface ClAllocationDetailDao extends BaseMapper<ClAllocationDetailEntity> {

    ClAllocationDetailEntity getCurrentAllocationByCollectionNo(String collectionNo);

    ClAllocationDetailEntity getLatestRecordByCollectionNoAndRepaymentDate(String collectionNo, Date repaymentDate);

    ClAllocationDetailEntity getLatestByCollectionNoAndLessThanDate(String collectionNo, Date repaymentDate);

    /**
     * 获取未完结的订单
     *
     * @param batchNo
     * @return
     */
    List<ClAllocationDetailEntity> getListByBatchNo(String batchNo);

    List<ClAllocationDetailEntity> getListByBatchNosAndPage(List<String> batchNos, Integer startIndex, Integer pageSize);

    Integer countByBatchNosAndPage(List<String> batchNos);

    List<ClAllocationInfoEntity> selectAllocationFullInfoList(Map<String, Object> params, Page page);

    List<ClAllocationInfoEntity> selectAllocationFullInfoList(Map<String, Object> params, Page page, Integer totalCount);

    List<ClOrderAllocationEntity> selectOrderAllocationList(Map<String, Object> params, Page page);

    List<ClOrderAllocationEntity> selectCollectionAllocationHistoryList(String userCode);

    List<UniqueStatsVo> getAgentUniqueStats(String stageCode, Date startDate, Date endDate, String merchantCode);

    List<UniqueStatsVo> getAgentAllStats(Date startDate, Date endDate, Integer adminId, String merchantCode);

    List<UniqueStatsVo> getAgentAllStatsGroup(String stageCode, Date startDate, Date endDate, String merchantCode);

    List<ClAllocationDetailEntity> getListByCollectionNo(String collectionNo);

    Integer updateStatusByBatchNoAndStatus(String batchNo, List<Integer> sourceStatus, Integer targetStatus);

    void updateStatusByAllocationNosAndStatus(List<String> allocationNos, List<Integer> sourceStatus, Integer targetStatus);

    ClCountInfoEntity selectAgentWorkStats(Integer adminId, Date startDate, Date endDate);

    /**
     * 把当前催收单的分单 id > 指定值的 status=0 的置为无效4
     *
     * @return
     */
    int updateAllocationInvalid(String collectionNo, long id);

    /**
     * 查询代理人 当日新增分单数
     *
     * @param merchantCode
     * @param date
     * @param overdueDays
     * @return
     */
    List<ClDailyOrderCountEntity> selectAgentDailyOrderCountList(String merchantCode, Date date, Integer overdueDays);

}
